/*  ----------------------------------------------------------------------------
 *  Arello Mobile
 *  Fast 3d Engine
 *  ----------------------------------------------------------------------------
 * Except where otherwise noted, this work is licensed under
 * http://creativecommons.org/licenses/by/3.0
 */

#include "../threads.h"
#include <win32/win32.h>

namespace liba
{
namespace threads
{

int interlocked_increment(counter_type * value)
{
	return InterlockedIncrement( reinterpret_cast<long *>( value ) );
}

int interlocked_decrement(counter_type * value)
{
	return InterlockedDecrement( reinterpret_cast<long *>( value ) );
}

void sleep(int time_ms)
{
	Sleep( time_ms );
}

__int64 get_precise_tick_count()
{
	LARGE_INTEGER now;
	if( !QueryPerformanceCounter( &now ) )
		return GetTickCount();
	return now.QuadPart;
}

double get_precise_tick_time()
{
	LARGE_INTEGER freq;
	if( !QueryPerformanceFrequency( &freq ) )
		return 0.001;
	if( freq.QuadPart == 0 )
		return 0.001;
	return 1.0 / freq.QuadPart;
}

} //namespace threads
} //namespace liba

